package com.example.demo.controller;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/test")
public class TestController {
	
	
	private static final Logger logger = LoggerFactory.getLogger(TestController.class);
	
	@GetMapping(value ="test" )
	@ResponseBody
	public Object testGetData() throws Exception {
		//get dbconnection
		 Connection connection = DBUtil.getConnection();
		//excute sql
		 String sql = "select * from goodtbl where price >90";
//		 PreparedStatement preStatement = connection.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
//         resultSet = preStatement.executeQuery();
		 ResultSet rs = DBUtil.executeQuery(connection,sql);
		 rs.last(); 
		 int rowCount = rs.getRow();
         System.out.println("表一共有"+rowCount+"记录");   
//		 try {
//	            if (rs.next()) {
//	                String str = rs.getString(2);
//	                System.out.println(str);
//	            }
//	        } catch (SQLException e) {
//	            e.printStackTrace();
//	        } finally {
//	        }
		//
		return null;
		
	}
	
	@GetMapping(value ="close" )
	@ResponseBody
	public Object closeDb() throws Exception {
		DBUtil.closeConnection();
		return null;
		
	}

}
